package com.chy.order_meal.service;

import com.chy.order_meal.dao.GoodsDao;
import com.chy.order_meal.dao.GoodsTypeDao;
import com.chy.order_meal.po.Goods;
import com.chy.order_meal.po.GoodsType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private GoodsTypeDao goodsTypeDao;

    public List<GoodsType> getGoodsByResId(Integer resturantId){
        List<GoodsType> result = new ArrayList<>();
        List<GoodsType> goodsTypes = goodsTypeDao.findAllByResturantId(resturantId);
        for(GoodsType goodsType:goodsTypes){
            Integer typeId = goodsType.getId();
            List<Goods> goodsList = goodsDao.findAllByGoodsType(typeId);
            goodsType.setGoods(goodsList);
            if(goodsList!=null && goodsList.size()>0){
                result.add(goodsType);
            }
        }
        return result;

    }

}
